using System;
using System.Runtime.Serialization;

namespace KodeIT.Web
{
    /// <summary>
    /// This class represents the exception thrown when an http header name is not supported by the IIS version.
    /// </summary>
    [Serializable]
    public class NotSupportedHeaderException : Exception
    {
        private string _headerName;

        /// <summary>
        /// Creates an instance of the <see cref="NotSupportedHeaderException"/> class.
        /// </summary>
        public NotSupportedHeaderException()
            : base()
        {
        }

        /// <summary>
        /// Creates an instance of the <see cref="NotSupportedHeaderException"/> class.
        /// </summary>
        /// <param name="message">The message associated with the exception.</param>
        public NotSupportedHeaderException(string message)
            : base(message)
        {
        }

        /// <summary>
        /// Creates an instance of the <see cref="NotSupportedHeaderException"/> class.
        /// </summary>
        /// <param name="headerName">The http header name that caused the exception.</param>
        /// <param name="nativeError">The native error associated with the exception.</param>
        public NotSupportedHeaderException(string headerName, int nativeError)
            : base(String.Format("The header name '{0}' is not supported by the HTTP version", headerName), new NativeException(nativeError))
        {
            _headerName = headerName;
        }

        /// <summary>
        /// Creates an instance of the <see cref="NotSupportedHeaderException"/> class.
        /// </summary>
        /// <param name="message">The message associated with the exception.</param>
        /// <param name="innerException">The inner exception to associate with the exception.</param>
        public NotSupportedHeaderException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        /// <summary>
        /// Creates an instance of the <see cref="NotSupportedHeaderException"/> class.
        /// </summary>
        /// <param name="info">The serialization information instance.</param>
        /// <param name="context">The streaming context instance.</param>
        protected NotSupportedHeaderException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        /// <summary>
        /// Gets the http header name that caused the exception to be thrown.
        /// </summary>
        public string HeaderName
        {
            get { return _headerName; }
        }
    }
}
